package com.xia.service.impl;

import com.xia.mapper.ReaderMapper;
import com.xia.pojo.Reader;
import com.xia.service.ReaderService;
import com.xia.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReaderServiceImpl implements ReaderService {

    @Autowired
    public ReaderMapper readerMapper;

    @Override
    public Integer readerQueryByReaderId(Integer readerId) {
        return readerMapper.readerQueryByReaderId(readerId);
    }

    @Override
    public void readerRegister(Reader reader) {
        readerMapper.readerRegister(reader);
    }

    @Override
    public Reader readerLoginQuery(Map<String, Object> map) {
        return readerMapper.readerLoginQuery(map);
    }

    @Override
    public PageBean<Reader> readerQueryList(Map<String, Object> map) {

        PageBean<Reader> pageBean = new PageBean<>((Integer) map.get("pageNo"), (Integer) map.get("pageSize"));
        Integer startIndex = pageBean.getStartIndex();
        map.put("startIndex", startIndex);
        List<Reader> readerList = readerMapper.readerQueryList(map);
        pageBean.setData(readerList);
        // 总数据条数
        Integer totalSize = readerMapper.readerQueryCount(map);
        pageBean.setPageSize(totalSize);
        return pageBean;
    }

    @Override
    public Reader readerQueryById(Integer readerId) {
        return readerMapper.readerQueryById(readerId);
    }

    @Override
    public void updateReader(Reader reader) {
        readerMapper.updateReader(reader);
    }

    @Override
    public void delReader(Integer id) {
        readerMapper.delReader(id);
    }

    @Override
    public void editPwd(Map<String, Object> map) {
        readerMapper.editPwd(map);
    }

    @Override
    public Integer checkPwd(Reader reader) {
        return readerMapper.checkPwd(reader);
    }

}
